package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.Process;
import com.qidianit.mes.pojo.pro.Workflow;
import com.qidianit.mes.pro.service.ProcessService;
import com.qidianit.mes.pro.service.WorkflowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/workflow")
@CrossOrigin
public class WorkflowController {
    @Autowired
    private WorkflowService workflowService;
    @GetMapping("page")
    public Result<PageInfo<Workflow>>
    list(Workflow  workflow, @RequestParam(defaultValue = "1")int page,
                            @RequestParam(defaultValue = "10")int size){
        return workflowService.selectList(workflow,page,size);
    }

    @GetMapping("/code/{code}")
    public Result<Workflow> selectByCode(@PathVariable("code") String workflowCode){
        return workflowService.selectByCode(workflowCode);
    }

    @PostMapping("/add")
    public Result<Workflow> saveWorkflow(@RequestBody Workflow workflow){
        return workflowService.saveWorkflow(workflow);
    }


    @PutMapping("/update")
    public Result<Workflow> updateWorkflow(@RequestBody Workflow workflow){
        return workflowService.updateWorkflow(workflow);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        return workflowService.deleteById(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDelete(Long[] id){
        return workflowService.batchDelete(id);
    }

}
